<?php
	session_start();
	
	
	if(isset($_REQUEST['action'])){
		include 'operations/connection.php';	
		$type=$_REQUEST['type'];
		if ($type=='11'){
			$idapprovedoc=$_REQUEST['idapprovedoc'];
			$listapprove=$_SESSION['listapprove'];
		
			$a= (string)(microtime(true)*1000);
			$b=split('\.',$a);
			$idgroupapprove= $b[0];
			if (count($listapprove)>0){
				// update approvedoc
				$sql="UPDATE approvedoc SET IDGroupApprove='$idgroupapprove', IDStatus='2' WHERE (IDApproveDoc='$idapprovedoc')";
				mysql_query($sql);
				foreach ($listapprove as $approve=>$abc){
			
					$sql="INSERT INTO `listapprove` (`IDGroupApprove`, `IDEmployee`, `IDtypeApprove`, `Order`, `IDStatus`) VALUES ('$idgroupapprove', '$approve', '$type', '1', '2')";
					mysql_query($sql);
					
				
				}
				header("Location: mydocument.php?content=list-mydocument-meeting-sending-content");
			}
		}else{
			$idapprovedoc=$_REQUEST['idapprovedoc'];
			$listapprove=$_SESSION['listapprove'];
			$listapprovename=$_SESSION['listapprovename'];
			$a= (string)(microtime(true)*1000);
			$b=split('\.',$a);
			$idgroupapprove= $b[0];
			if (count($listapprove)>0){
				// update approvedoc
				$sql="UPDATE approvedoc SET IDGroupApprove='$idgroupapprove', IDStatus='2' WHERE (IDApproveDoc='$idapprovedoc')";
			
				mysql_query($sql);
				
				// insert  list group approve
				$i=1;
				foreach ($listapprove as $approve=>$abc){
					if($i==1){
						$sql="INSERT INTO `listapprove` (`IDGroupApprove`, `IDEmployee`, `IDtypeApprove`, `Order`, `IDStatus`) VALUES ('$idgroupapprove', '$approve', '$type', '$i', '2')";
						mysql_query($sql);
					}else{
						$sql="INSERT INTO `listapprove` (`IDGroupApprove`, `IDEmployee`, `IDtypeApprove`, `Order`, `IDStatus`) VALUES ('$idgroupapprove', '$approve', '$type', '$i', '4')";
						mysql_query($sql);
					}
					foreach ($abc as $hienthi){
						$sql="INSERT INTO list_reference (id_employee,id_manager,id_group,id_status) VALUES ('$hienthi[0]', '$approve', '$idgroupapprove', '4')";
						mysql_query($sql);
					}
					$i=$i+1;
				}
				if($_REQUEST['group']!=''){
					$sql="INSERT INTO groupapprove (id,employee_id,name) VALUES ('$idgroupapprove', '".$_SESSION['IDEmployee']."', '".$_REQUEST['group']."')";
					mysql_query($sql);
				}
				mysql_close($connection);
				
				header("Location: mydocument.php?content=list-mydocument-sending-content");
			}
		}
	}
	
	
	include 'operations/connection.php';
	$idapprovedoc=$_REQUEST['idapprovedoc'];
	$type=$_REQUEST['type'];

	$lang=$_SESSION['lang'];
	if($lang=='')
		$lang='EN';
	include("operations/get_lang.php");
	$value = getlang();
	include($value);
	
	$content = "content/approve-content.php";
	if($type=='11'){
		$content = "content/approvemore-content.php";
	}
	
	
	if(!$_SESSION['user'])
	{
		header( 'Location: login.php' );
	}
	else 
	{		
		$username = $_SESSION['fullname'];
		$id_employee = $_SESSION['IDEmployee'];
	}
	echo $_SESSION['back']; 
	$title = $_SESSION['browser'];
	
	
	if($_SESSION['role']==1){
		
		require("MainTemplateAdmin.php");
	}
	else{
		require("MainTemplate.php");
	}
?>